package faker

import (
	"math/rand"
	"time"
)

var  letter = []string{
	"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
	"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
}

// RandInt random int number
func RandInt(start int, end int) int {

	rand.Seed(time.Now().UnixNano() + int64(rand.Intn(100)))
	//rand.Seed(time.Now().UnixMicro())
	return start + rand.Intn(end + 1 - start)
}

func RandStringLowerCase(length int) string {
	var (
		r *rand.Rand
		bytes []byte
		i int
	)

	if length <= 0 {
		panic("len Cannot be less than or equal to 0")
	}
	r = rand.New(rand.NewSource(time.Now().UnixNano()))
	bytes = make([]byte, length)
	for i = 0; i < length; i++ {
		bytes[i] = byte(r.Intn(26) + 97)
	}
	return string(bytes)
}

func RandStringUpperCase(length int) string {
	var (
		r *rand.Rand
		bytes []byte
		i int
	)

	if length <= 0 {
		panic("len Cannot be less than or equal to 0")
	}
	r = rand.New(rand.NewSource(time.Now().UnixNano()))
	bytes = make([]byte, length)
	for i = 0; i < length; i++ {
		bytes[i] = byte(r.Intn(26) + 65)
	}
	return string(bytes)
}

func RandString(length int) string {

	var (
		r *rand.Rand
		str string
		i int
	)

	if length <= 0 {
		panic("len Cannot be less than or equal to 0")
	}
	r = rand.New(rand.NewSource(time.Now().UnixNano() + int64(rand.Intn(100))))
	for i = 0; i < length; i++ {
		str += letter[r.Intn(len(letter)-1)]
	}
	return str
}
